<template>
  <div>
    <IncreServiceFeeFieldEdit ref="openIncreServiceFeeFieldEdit"  @refresh="refresh"></IncreServiceFeeFieldEdit>
    <IncreServiceFeeFieldAdd ref="openIncreServiceFeeFieldAdd"  @refresh="refresh"></IncreServiceFeeFieldAdd>
      <el-dialog title="信息" :visible.sync="openIncreServiceFeeField" width="800px" append-to-body :destroy-on-close="true" :before-close="beforeClose">
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button  type="primary" plain size="mini" @click="handleAdd" >添加</el-button>
            </el-col>
        </el-row>
        <el-table
          v-loading="loading"
          row-key="id"
          :data="increServiceFeeItemList"
        >
            <af-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100" fixed="left">
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        type="text"
                        @click="handleEdit(scope.row)"
                    >修改</el-button>
                    <el-button
                        size="mini"
                        type="text"
                        @click="handleDelete(scope.row)"
                    >删除</el-button>
                </template>
            </af-table-column>
            <af-table-column label="收费项目" prop="name"/>
        </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { increServiceFeeItem, delChargeItems } from "@/api/storage/commonGoods/increServiceFee";
import IncreServiceFeeFieldEdit from './increServiceFeeFieldEdit.vue'
import IncreServiceFeeFieldAdd from './increServiceFeeFieldAdd.vue'

export default {
  name: "IncreServiceFeeField",
  components:{ IncreServiceFeeFieldEdit, IncreServiceFeeFieldAdd },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //列表加载
      loading: true,
      //打开弹窗状态
      openIncreServiceFeeField: false,
      //删除参数
      delelteParams: {
       idd:""
      },
      //增值服务收费明细数据
      increServiceFeeItemList:[],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  methods: {
    /** 查询 */
    getList() {
      this.loading=true
      increServiceFeeItem({}).then(response => {
        this.increServiceFeeItemList = response.data;
        this.loading=false
      })
    },
    /**删除 */
    chargeItemsDel() {
      this.$modal.loading("数据正在删除中，请稍等...")
      delChargeItems(this.delelteParams).then(response => {
        this.$modal.closeLoading()
        this.$modal.msgSuccess('删除成功！')
        this.getList()
      }).catch(()=> {
        this.$modal.closeLoading()
      })
    },
    /**编辑 */
    handleEdit(data) {
      this.$refs.openIncreServiceFeeFieldEdit.open(data)
    },
    /**添加 */
    handleAdd() {
        this.$refs.openIncreServiceFeeFieldAdd.open()
    },
    /**删除 */
    handleDelete(row) {
      this.delelteParams.idd = row.id
      this.$modal.confirm("是否删除记录？").then(() => {
        this.chargeItemsDel()
      }).catch(() => {})
    },
    /** 重置按钮操作 */
    reset() {
      this.increServiceFeeItemList =[]
      this.pageNum = 1
      this.total = 0
      this.getList()
    },
    refresh() {
      this.getList()
    },
     /**改变窗口状态 */
    changeIncreServiceFeeField() {
      this.openIncreServiceFeeField = !this.openIncreServiceFeeField;
    },
    /**关闭弹窗 */
    close() {
      this.changeIncreServiceFeeField()
      this.reset()
    },
    /**关闭弹窗前 */
    beforeClose(done) {
      this.close()
      done()
    },
    /**打开弹窗 */
    open() {
      this.changeIncreServiceFeeField()
      this.getList()
    }
  }
};
</script>
